package com.example.wwk.graduationpractice.NetDataUtils;

import android.util.Log;

import com.example.wwk.graduationpractice.Bean.ComeMsgBean;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * Created by wwk on 2017/3/25.
 */

public class LitePalUtils {
    public static void addData(String receiveUser,String userName,int unreadCount) {
        //一开始加入消息列表中所有成员
        ComeMsgBean msgCount = new ComeMsgBean();
        msgCount.setReceiver(receiveUser);
        msgCount.setUserName(userName);
        msgCount.setUnreadCount(unreadCount);
        Log.d("123", "querryData: to "+msgCount.getReceiver()+" from "+msgCount.getUserName()+" count: "+msgCount.getUnreadCount());
        msgCount.save();

    }
    public static void updateData(int count,String receiveUser,String user){
        ComeMsgBean comeMsgBean = new ComeMsgBean();
        comeMsgBean.setUnreadCount(count);
        comeMsgBean.updateAll("receiver = ? and userName = ?",receiveUser,user);
    }
    public static List<ComeMsgBean> querryData(String receiveUser,String userName) {//查询条件作为参数
        List<ComeMsgBean> msgCounts = DataSupport.where("receiver = ? and userName = ?", receiveUser,userName).find(ComeMsgBean.class);
//        for(ComeMsgBean comeMsgBean : msgCounts){
//            Log.d("123", "querryData: to "+comeMsgBean.getReceiver()+" from "+comeMsgBean.getUserName()+" count: "+comeMsgBean.getUnreadCount());
//        }
        return msgCounts;
    }
    public static void deleteData(String receiver,String user){//删除表中符合条件的数据
        DataSupport.deleteAll(ComeMsgBean.class, "receiver = ? and userName = ?",receiver, user);
    }
    public static void deleteAllData(Class<?> tableName) {
        DataSupport.deleteAll(tableName);//清空表中的数据
    }

}
